#include <iostream>
using namespace std;
#include <vector>
#include <string.h>

class Teacher
{
public:
        Teacher(char *name, int age)
        {
                m_pname = new char[strlen(name) + 1];
                strcpy(m_pname, name);
                m_age = age;
        }
        ~Teacher()
        {
                if(m_pname != NULL)
                {
                        delete [] m_pname;
                        m_pname = NULL;
                        m_age = 0;
                }
        }
        Teacher(const Teacher &obj)
        {
                m_pname = new char[strlen(obj.m_pname)+1];
                strcpy(m_pname , obj.m_pname);
                m_age = obj.m_age;
        }
        Teacher& operator=(const Teacher &obj)
        {
                //先把旧的内存释放掉
                if(m_pname != NULL)
                {
                        delete[] m_pname;
                        m_pname = NULL;
                        m_age = 0;
                }
                //根据obj的大小分配内存 拷贝数据
                m_pname = new char[strlen(obj.m_pname)+1];
                strcpy(m_pname , obj.m_pname);
                m_age = obj.m_age;
                return *this;
        }
        void printT()
        {
                cout<<m_pname << " "<<m_age<<endl;
        }
private:
        char *m_pname;
        int m_age;
};

void test1()
{
        Teacher t1("t1", 31);
        t1.printT();

        vector<Teacher> v1;
        v1.push_back(t1); //把t1拷贝一份 存入到容器中了
        
}

int main(int argc, char const *argv[])
{
        test1();
        return 0;
}
